package fun.sanguo.webserver;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 本地静态文件映射
 *
 * @author ZYP
 * @date 2023-04-23
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${storage.server}")
    private String storageServer;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry resourceHandlerRegistry) {
        resourceHandlerRegistry
                .addResourceHandler("/storage/**")
                .addResourceLocations("file:" + this.storageServer)
                .setCachePeriod(3600);
    }
}
